using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Ssb
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class MenuItem 
        : Microsoft.Xna.Framework.DrawableGameComponent
    {
        public MenuItem(Game game)
            : base(game)
        {
            Initialize();
        }

        public bool Active { get; set; }

        public Texture2D activeTexture;
        public Texture2D itemTexture;

        public Vector2 coords;

        public Menu link;
        public Menu owner;

        private SpriteBatch sb;
        

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            this.sb = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            
            base.Initialize();
        }

        public override void Draw(GameTime gt)
        {
            if (Active)
                ((SpriteBatch)Game.Services.GetService(typeof(SpriteBatch))).Draw(activeTexture, coords, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.000001f);
            else
                ((SpriteBatch)Game.Services.GetService(typeof(SpriteBatch))).Draw(itemTexture, coords, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0.0000001f);
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            MouseState ms = Mouse.GetState();

            if (owner.cursor.PointsToRectangle(new Rectangle((int)this.coords.X, (int)this.coords.Y, this.activeTexture.Width, this.activeTexture.Height)) && ms.LeftButton == ButtonState.Pressed)
            {
                SsbPC game = (SsbPC)Game;

                if (this.link != null)
                {
                    game.currentMenu = this.link;
                    game.currentMenu.cursor.X = this.owner.cursor.X;
                    game.currentMenu.cursor.Y = this.owner.cursor.Y;
                }
            }

            if (owner.cursor.PointsToRectangle(new Rectangle((int)this.coords.X, (int)this.coords.Y, this.activeTexture.Width, this.activeTexture.Height)))
                this.Active = true;
            else
                this.Active = false;


            base.Update(gameTime);
        }
    }
}